import axios from "axios"
import nProgress from "nprogress"
import "nprogress/nprogress.css"
import {GetUserTempId,getToken} from "@/utils/auth"

let instance = axios.create({
    baseURL:"/sph",
    timeout:5000
})

instance.interceptors.request.use((config)=>{

    nProgress.start()

    config.headers.token = getToken()

    config.headers.userTempId = GetUserTempId()

    return config
})

instance.interceptors.response.use((response)=>{

    nProgress.done()

    switch (response.data.code) {
        case 200:
            return response.data.data
    
        default:
            return response.data
    }
    },
    (error)=>{
        nProgress.done()
            console.log(error.message);
            return new Promise(()=>{})
    }

)


export default instance